package priv.bruce.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.entry.MovieScore;
import priv.bruce.service.JudegeScore4DetailService;

public class JudgeScore4DetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	JudegeScore4DetailService judegeScore4DetailService=new JudegeScore4DetailService();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		int uid=Integer.parseInt(request.getParameter("user_id"));
		int mid=Integer.parseInt(request.getParameter("movie_id"));
		
		try {
			List<MovieScore> judegeScore = judegeScore4DetailService.JudegeScore(uid,mid);
			if (judegeScore.size()>=1) {
				response.getWriter().append(JSON.toJSONString(-1));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("application/json;charset=utf-8");
		int uid=Integer.parseInt(request.getParameter("user_id"));
		int mid=Integer.parseInt(request.getParameter("movie_id"));
		
		try {
			List<MovieScore> judegeScore = judegeScore4DetailService.JudegeScore(mid,uid);
			if (judegeScore.size()>=1) {
				response.getWriter().append(JSON.toJSONString(judegeScore));
			}else {
				response.getWriter().append(JSON.toJSONString(0));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	
	}

}
